package com.chzc.fm.duotin.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.bean.home.RecommendDataList;
import com.chzc.fm.duotin.ui.home.utils.JumpManager;
import com.chzc.fm.duotin.utils.ImageUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Administrator on 2016/6/24.
 */
public class HomeItem extends RelativeLayout {

//    private LayoutInflater inflater;
    ImageView ivContent;
    TextView tvTitle,tvContent;
    RelativeLayout mRlRoot;
    RecommendDataList data;
    Context context ;
    public HomeItem(Context context, RecommendDataList data) {
        super(context);
        this.data = data;
        this.context = context;
        initView(context);
        initListener();
        setRecommendData(data);
    }

    private void initListener() {

        mRlRoot.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                JumpManager.jumpToPlayer1(context,data.getItem_value());

            }
        });


    }

    public HomeItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        initView(context);
        initListener();
    }
    private void initView(Context context){

        inflate(context, R.layout.fragment_home_item,this);
        ivContent = (ImageView) findViewById(R.id.ivConent);
        tvTitle = (TextView) findViewById(R.id.tvTitle);
        tvContent = (TextView) findViewById(R.id.tv_content);
        mRlRoot = (RelativeLayout) findViewById(R.id.rl_root);
    }
    public void setRecommendData(RecommendDataList data){

        //设置圆角图片
        this.data=data;
        ImageLoader.getInstance().displayImage(data.getImage_url(),ivContent,ImageUtil.getRoundOptions());
        tvTitle.setText(data.getSub_title());
        tvContent.setText(data.getTitle());

    }
}
